<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css"
	rel="stylesheet" type="text/css" />
<link href="css/table.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/widgets.js"></script>

<script type="text/javascript">
	
	function Click_Save() {
		$('#org_tcID')[0].value = getValue('tcID');
		$('#org_uID')[0].value = getValue('uID');

		//表示有輸入，要開始查詢
		x = $('#q_form').serializeArray();
		$.ajax({
			type : 'post',
			url : 'DuplicateCheck',
			data : x,
			dataType : 'text',
			success : function(queryResult) {
				if (queryResult > 0) {
					alert("測試案例ID重覆了");
				} else {
					/**	下面這三行，是將CKEDITOR內部的網頁語法，寫入要送出的三個變數 **/
					$('#tcKeyPoint')[0].value = CKEDITOR.instances.editor_tcKeyPoint.getData();
					$('#tcProcess')[0].value = CKEDITOR.instances.editor_tcProcess.getData();
					$('#tcResExp')[0].value = CKEDITOR.instances.editor_tcResExp.getData();
					$('#tcTestData')[0].value = CKEDITOR.instances.editor_tcTestData.getData();
					$('#tcNumKeyPoint')[0].value = $('#numKeyPoint').attr("value");
					
					if ($('#isAnalizeHierach').is(':checked')) {
						$('#submitIsAnalizeHierach')[0].value = "1";
					} else {
						$('#submitIsAnalizeHierach')[0].value = "0";
					}
					x = $('#q_form').serializeArray();
					$.ajax({
						type : 'post',
						url : 'ReplicateTC',
						data : x,
						dataType : 'text',
						success : function(queryResult) {
							alert(queryResult);
						}, error : function() {
							alert('使用AJax失敗');
						}
					});
				}
			}, error : function() {
				alert('使用AJax失敗');
			}
		});
	}
	
	$(document).ready(function() {
		$('button').button();
		$("#loginUser")[0].value = $.cookie("userID");
		
		/* 初始化畫面的值 */
		$('#tcID')[0].value = getValue('tcID');
		$('#tcName')[0].value = getValue('tcName');
		$('#comingTCID')[0].value = getValue('tcID');
		x = $('#queryContent').serializeArray();
		$.ajax({
			type : 'post',
			url : 'GetTC',
			data : x,
			dataType : 'json',
			success : function(queryResult) {
				$.each(queryResult,function(i,res) {
					$("#numKeyPoint")[0].value = res.numKeyPoint;
					CKEDITOR.instances.editor_tcKeyPoint.setData(res.tcKeyPoint);	
					CKEDITOR.instances.editor_tcProcess.setData(res.tcProcess);
					CKEDITOR.instances.editor_tcResExp.setData(res.tcResExp);
					CKEDITOR.instances.editor_tcTestData.setData(res.tcTestData);
				}); 
			}
		});
	});

	function getValue(val) {
		var url = window.location.toString(); //取得當前網址
		if (url.indexOf("?") != -1) {
			var ary = url.split("?")[1].split("&");
			//取得"?"右邊網址後利用"&"分割字串存入ary陣列 ["a=1","b=2","c=3"]
			for ( var i in ary) {
				//取得陣列長度去跑迴圈，如:網址有三個參數，則會跑三次
				str = ary[i].split("=")[0];
				//取得參數"="左邊的值存入str變數中
				if (str == val) {
					str_value = decodeURI(ary[i].split("=")[1]);
				}
			}
		}

		return str_value;
	}
	
</script>
<title>複製測試案例</title>
</head>
<body>
	************************
	<br /> &nbsp;&nbsp;&nbsp;~ 複製測試案例 ~
	<br /> ************************
	<br />
	<p>
		<button id='but_tc_u' type="button" onClick="Click_Save()">儲存</button>
		&nbsp;
	<p />
	<br />
	<hr />
	<form id='q_form' method="post">

		<table id='replicateTCTableOne'>
			<tr>
				<th><div align="right">測試案例ID：</div></th>
				<td><input type="text" id='tcID' name='tcID' /><input
					type="checkbox" id="isAnalizeHierach" name="isAnalizeHierach" />解析階層<dfn id="cautionText">(以 _ 為分階符號)</dfn></td>
			</tr>
			<tr>
				<th><div align="right">案例名稱：</div></th>
				<td><input type="text" id='tcName' name='tcName' /></td>
			</tr>
			<tr>
				<th><div align="right">驗證重點數：</div></th>
				<td><input type="text" size="2" id='numKeyPoint' name='numKeyPoint' onkeyup="return ValidateNumber(this,value,false)" /></td>
			</tr>
		</table>
		<p />
		<table id='replicateTCTableTwo'>
			<thead id='replicateTCTableTwo_h'>
				<tr>
					<th>驗証重點</th>
					<th>測試資料</th>
					<th>測試流程</th>
					<th>預期結果</th>
				</tr>
			</thead>

			<tbody id='replicateTCTableTwo_b'>
				<tr>
					<td><textarea id="editor_tcKeyPoint" name="editor_tcKeyPoint"></textarea></td>
					<td><textarea id="editor_tcTestData" name="editor_tcTestData"></textarea></td>
					<td><textarea id="editor_tcProcess" name="editor_tcProcess"></textarea></td>
					<td><textarea id="editor_tcResExp" name="editor_tcResExp"></textarea></td>
				</tr>
			</tbody>
		</table>
		<input type="hidden" id="tcKeyPoint" name="tcKeyPoint" >
		<input type="hidden" id="tcProcess" name="tcProcess" >
		<input type="hidden" id="tcResExp" name="tcResExp" >
		<input type="hidden" id="tcTestData" name="tcTestData" >
		<input type="hidden" id="tcNumKeyPoint" name="tcNumKeyPoint" >
		<input type="hidden" id="submitIsAnalizeHierach" name="submitIsAnalizeHierach" >
		<input type="hidden" id="org_tcID" name="org_tcID" /> 
		<input type="hidden" id="org_uID" name="org_uID" />
		<input type="hidden" id="loginUser" name="loginUser" >
	</form>
	<script type="text/javascript">
		CKEDITOR.replace("editor_tcKeyPoint");
		CKEDITOR.replace("editor_tcProcess");
		CKEDITOR.replace("editor_tcResExp");
		CKEDITOR.replace("editor_tcTestData");
	</script>
	<form id="queryContent" action="post">
		<input type="hidden" id="comingUID" name="comingUID" />
		<input type="hidden" id="comingTCID" name="comingTCID" />
	</form>

</body>
</html>